package org.toools.gwt.demo.jpa;

import java.util.Collection;
import java.util.Vector;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import net.sf.gilead.pojo.java5.LightEntity;

/**
 *
 * @author stefan asseg
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "Disposer.getAll", query = "SELECT a FROM Disposer a"),
    @NamedQuery(name = "Disposer.getById", query = "SELECT a FROM Disposer a WHERE a.id = :id"),
    @NamedQuery(name = "Disposer.getByName", query = "SELECT a FROM Disposer a WHERE a.name = :name")
})
public class Disposer extends LightEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Integer id;
    private String name;
    @OneToMany(mappedBy = "disposer", cascade = CascadeType.ALL)
    private Collection<Container> containers = new Vector<Container>();

    public Disposer() {
    }

    public Disposer(String name) {
        this.name = name;
    }

    public Disposer(String name, Collection<Container> containers) {
        this.containers = containers;
        this.name = name;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Collection<Container> getContainers() {
        return containers;
    }

    public void setContainers(Collection<Container> containers) {
        this.containers = containers;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Disposer)) {
            return false;
        }
        Disposer other = (Disposer) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Disposer [id = " + id + "] [container_id = " + containers + "] [content = " + name + "]";
    }
}
